<template>
  <div>
    <div style="margin: 30px 0">
      <a-input-search placeholder="请输入搜索内容" style="width: 200px;margin-right: 10px" enter-button @search="onSearch" />
    </div>
    <a-table
        :columns="columns"
        :data-source="data"
        :pagination="filterList"
        @change="handleChangeCurrent"
    >
      <!-- 操作自定义样式 -->
      <div slot="action" slot-scope="text,record">
        <a-button type="danger" icon="delete" @click="del(record.uid)">删除</a-button>
      </div>
    </a-table>
  </div>
</template>

<script>
import { reviewDel, reviewList } from '@/services/photoList';

const columns = [
  {
    title: '销售ID',
    dataIndex: 'sid',
    key: 'sid',
    align: 'center'
  },
  {
    title: '销售名称',
    dataIndex: 'salesman',
    key: 'salesman',
    ellipsis: true,
    align: 'center',
  },
  {
    title: '用户名称',
    dataIndex: 'username',
    key: 'username',
    align: 'center',
  },
  {
    title: '评论内容',
    dataIndex: 'remark',
    ellipsis: true,
    key: 'remark',
    align: 'center',
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    key: 'createTime',
    ellipsis: true,
    align: 'center',
  },
  {
    title: '操作',
    dataIndex: 'action',
    key: 'action',
    align: 'center',
    width: 210,
    scopedSlots: { customRender: 'action' }
  }
];

const data = [];
export default {
  name: 'UserComments',
  inject: ['reload'],
  data() {
    return {
      data,
      columns,
      filterList: {
        total: 0,
        pageNo: 1,
      },
      loading: false,
      selectedRowKeys: [],
    }
  },
  mounted() {
    this.reviewList()
  },
  methods: {
    reviewList() {
      const {pageNo} = this.filterList
      reviewList({pageNo}).then(res=>{
        this.data = res.data.result.records || {}
        this.filterList.total = res.data.result.total || 1
        this.loading = false;
      })
    },
    //  搜索
    onSearch(value) {
      reviewList({salesman: value}).then(res=>{
        this.data = res.data.result.records || {}
        this.filterList.total = res.data.result.total || 0
        this.loading = false;
      })
    },
    //  删除
    del(e) {
      reviewDel({id:e}).then(res=>{
        console.log(res)
        this.$message.success(res.data.message)
      })
      this.reload()
    },
    //  分页
    handleChangeCurrent(val) {
      this.filterList.pageNo = val.current
      this.reviewList()
    },
  }
};
</script>

<style scoped>

</style>
